package com.lxyk.yygh.hosp.controller.front;

import com.lxyk.yygh.common.result.Result;
import com.lxyk.yygh.hosp.service.DepartmentService;
import com.lxyk.yygh.hosp.service.HospitalService;
import com.lxyk.yygh.hosp.service.HospitalSetService;
import com.lxyk.yygh.hosp.service.ScheduleService;
import com.lxyk.yygh.model.hosp.Hospital;
import com.lxyk.yygh.vo.hosp.DepartmentVo;
import com.lxyk.yygh.vo.hosp.HospitalQueryVo;
import com.lxyk.yygh.vo.hosp.ScheduleOrderVo;
import com.lxyk.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api("医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    //医院设置service
    @Autowired
    private HospitalSetService hospitalSetService;

    /**
     * 查询医院列表
     */
    @ApiOperation(value = "查询医院列表")
    @PostMapping("/findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable Integer page, @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo){
        Page<Hospital> listHosp = hospitalService.listHosp(page, limit, hospitalQueryVo);
        return Result.ok(listHosp);
    }

    /**
     * 根据医院名字模糊查询
     * @param hosname
     * @return
     */
    @ApiOperation(value="根据医院名字模糊查询")
    @GetMapping("/findByHosName/{hosname}")
    public Result findByHosName(@PathVariable String hosname){
        List<Hospital> list = hospitalService.findByHosName(hosname);
        return Result.ok(list);
    }

    /**
     * 医院详情
     * @param hoscode
     * @return
     */
    @ApiOperation(value="医院详情")
    @GetMapping("/{hoscode}")
    public Result hospitalDetail(@PathVariable String hoscode){

        Map<String, Object> detailMap = hospitalService.hospitalDetail(hoscode);
        return Result.ok(detailMap);
    }


    /**获取科室列表
     *
     * @return
     */
    @ApiOperation(value = "获取科室列表")
    @GetMapping("department/{hoscode}")
    public Result allDepartment(@PathVariable String hoscode){
        //接口复用
        List<DepartmentVo> deptList = departmentService.findDeptTree(hoscode);
        return Result.ok(deptList);
    }


    /**
     * 获取可预约排班数据
     * @param page
     * @param limit
     * @param hoscode
     * @param depcode
     * @return
     */
    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    /**
     * 获取排班数据
     * @param hoscode
     * @param depcode
     * @param workDate
     * @return
     */
    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    /**
     * "根据排班id获取排班数据
     * @param scheduleId
     * @return
     */
    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId) {
        return Result.ok(scheduleService.getScheduleById(scheduleId));
    }


    @ApiOperation(value="根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@ApiParam(name="scheduleId",value="排班id",required = true)
    @PathVariable("scheduleId") String scheduleId){

        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@ApiParam(name="hoscode",value="医院code",required = true)
                                    @PathVariable("hoscode") String hoscode){
        return hospitalSetService.getSignInfoVo(hoscode);
    }






}
